package com.ddwl.goods.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.goods.QueryGoodsProfitBo;
import com.ddwl.goods.service.ShopGoodsProfitService;
import com.ddwl.schema.bo.distr.SetGoodsProfitBo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.dist.GoodsProfitVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 类GoodsProfitController.java的实现描述：商品分润设置接口
 *
 * @author zach
 * @Date :2020-05-25 15:52.
 */
@Api(tags = "门店分润信息")
@RequestMapping("/shopProfit")
@RestController
public class ShopGoodsProfitController extends BaseController {

    @Resource
    private ShopGoodsProfitService shopGoodsProfitService;

    @PostMapping("/set")
    @Auth(product = BaseEnum.ProductEnum.SHOP_CONSOLE)
    @ApiOperation("设置商品分润")
    public RestVo SetGoodsProfitVo(@Valid @RequestBody SetGoodsProfitBo goodsProfitVo) {
        goodsProfitVo.setShopId(getShopId());
        shopGoodsProfitService.setGoodsProfit(goodsProfitVo);
        return RestVo.ok();
    }

    @DeleteMapping("/delete")
    @Auth(product = BaseEnum.ProductEnum.SHOP_CONSOLE)
    @ApiOperation("删除商品分润")
    public RestVo deleteGoodsProfitVo(@ApiParam(value = "商品分润id", required = true) @RequestParam String id ) {
        shopGoodsProfitService.deleteGoodsProfit(id,getShopId());
        return RestVo.ok();
    }

    @GetMapping("/query")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    @ApiOperation("查询商品分润信息")
    public RestVo<List<GoodsProfitVo>> queryGoodsProfitVo(@Valid QueryGoodsProfitBo queryGoodsProfitVo) {
        queryGoodsProfitVo.setShopId(getShopId());
        return RestVo.ok(shopGoodsProfitService.queryGoodsProfitVo(queryGoodsProfitVo));
    }

}
